package demo.wms.dao.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.zc.commons.base.Page;
import com.zc.commons.dao.ZcDao;

import demo.wms.dao.WmsProductsDAO;
import demo.wms.sqlbean.WmsProducts;

@Repository
public class WmsProductsDAOImpl<T> extends ZcDao<T> implements WmsProductsDAO {

    public Long searchPageWmsProductsNum(WmsProducts wmsproducts) throws SQLException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", wmsproducts);
        return (Long) find("WMS_PRODUCTS.searchPageWmsProductsNum", map);
    }

    public void searchPageWmsProducts(WmsProducts wmsproducts, Page<WmsProducts> page) throws SQLException {
        page.setTotalRow(searchPageWmsProductsNum(wmsproducts));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", wmsproducts);
        map.put("startrow", page.getStartRow());
        map.put("pagesize", page.getPageSize());
        map.put("pageable", page.getPageable());
        page.setRows(list("WMS_PRODUCTS.searchPageWmsProducts", map));
    }

    public void insertWmsProducts(WmsProducts record) throws SQLException {
        insert("WMS_PRODUCTS.insertWmsProducts", record);
    }

    public int updateWmsProducts(WmsProducts record) throws SQLException {
        int rows = update("WMS_PRODUCTS.updateWmsProducts", record);
        return rows;
    }

    public WmsProducts searchWmsProducts(Integer pid) throws SQLException {
        WmsProducts key = new WmsProducts();
        key.setPid(pid);
        WmsProducts record = (WmsProducts) find("WMS_PRODUCTS.selectWmsProducts", key);
        return record;
    }

    public int deleteWmsProducts(Integer pid) throws SQLException {
        WmsProducts key = new WmsProducts();
        key.setPid(pid);
        int rows = delete("WMS_PRODUCTS.deleteWmsProducts", key);
        return rows;
    }
}
